﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hutech.Authentication.Library.Web.Framework;
using Resources;
using Hutech.Authentication.Library.Business.WebHelpers;
using log4net;
using Hutech.Authentication.Library.Business;

namespace Hutech.CRM.Web.Controls.ManageRoleAndModule
{
    public partial class PopupAddNewItemPermission : System.Web.UI.UserControl
    {
        #region Cac su kien uy thac
        //Tao su kien uy thac
        public event EventHandler ReloadData;
        protected void onReloadData()
        {
            if (ReloadData != null)
            {
                ReloadData(this, new EventArgs());
            }
        }
        #endregion


        //Su kien xay ra dau tien... khai bao cac su kien dc dung trong popup
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //LinkButtonCancel.Click += new EventHandler(LinkButtonCancel_Click);
            ButtonSave.Click += new EventHandler(ButtonSave_Click);
            
        }



        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #region Show All information on popup
        public void Show(Guid RoleID)
        {
            ModalPopupAddNewItemPermission.Show(); //Hien thi popup
            _RoleID.Value = RoleID.ToString();

            populateText();

            LoadDropDownlistKindAction();
        }

        protected void populateText()
        {
            lblHead.Text = "Thêm quyền người dùng";
            TextBoxActionName.Text = string.Empty;
            TextBoxActionCommand.Text = string.Empty;
            TextBoxDescription.Text = string.Empty;
        }

        protected void LoadDropDownlistKindAction()
        {
            DropDownListKindAction.DataSource = Actions.GetAllKindAction();
            DropDownListKindAction.DataTextField = "ActionKindName";
            DropDownListKindAction.DataValueField = "ActionKindGuid";
            DropDownListKindAction.DataBind();
        }
        #endregion

        #region All Event
        void ButtonSave_Click(object sender, EventArgs e)
        {
            Actions action = new Actions();
            action.ActionKindGuid = new Guid(DropDownListKindAction.SelectedValue);
            action.ActionKindName = DropDownListKindAction.SelectedItem.ToString();
            action.ActionName = TextBoxActionName.Text;
            action.ActionCommand = TextBoxActionCommand.Text;
            action.Description = TextBoxDescription.Text;

            if (action.Save())
            {
                ModalPopupAddNewItemPermission.Hide();
                onReloadData();
            }
        }
        #endregion
    }
}
